﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using WebRSSBuilder.Core;
using System.Web;

namespace WebRSSBuilder.Web
{
    [ServiceContract(Namespace = "WebRSSBuilder.Web")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class WCFRSSDataSource
    {
        [OperationContract]
        public RSSFeed GetRssFeed(int FileID)
        {
            DomainServiceDB d = new DomainServiceDB();
            File f = d.GetFileByID(FileID);
            if (HttpContext.Current.User.Identity.IsAuthenticated)
                if (HttpContext.Current.User.IsInRole(f.aspnet_Roles.RoleName))
                    return new RSSFeedXLinqController().LoadRss(f.FileURL);
            else
                throw new Exception("Access Denied");
            return null;

        }
        [OperationContract]
        public bool UpdateRssFeed(RSSFeed feed, int FileID)
        {
            DomainServiceDB d = new DomainServiceDB();
            File f = d.GetFileByID(FileID);
            if (HttpContext.Current.User.Identity.IsAuthenticated)
                if (HttpContext.Current.User.IsInRole(f.aspnet_Roles.RoleName))
                {
                    new RSSFeedXLinqController().SaveFeed(feed);
                    return true;
                }

            throw new Exception("Access Denied");
            return false;
           
        }
    }
}
